﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Wicresoft.Common;
using Wicresoft.Framework.Organization;
using JDEduTrain.Framework.Business;
using JDEduTrain.Framework.Entity;


public partial class Page_NewLector : Wicresoft.Framework.Authentication.BasePage
{
    private Guid LectorID
    {
        get
        {
            if (Request["LectorID"] != null)
            {
                return new Guid(Request["LectorID"]);

            }
            return Guid.Empty;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = "新建讲师信息";


        if (!IsPostBack)
        {
            string path = Server.MapPath(@"~/Library/User/" + CurrentUser.Name);
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);//在指定路径下新建一个文件夹
            }
            tbBriefInfo.SetSecurityImageGalleryPath(@"~/Library/User/" + CurrentUser.Name);

            if (LectorID != Guid.Empty)
            {

                LectorInfo lector = new LectorInfo(LectorID);
                if (lector.Load())
                {
                    tbBackNvarchar1.Text = lector.BackNvarchar1;
                    tbBackNvarchar2.Text = lector.BackNvarchar2;
                    tbBackNvarchar3.Text = lector.BackNvarchar3;
                    tbBirthday.Text = lector.Birthday.ToShortDateString();
                    tbName.Text = lector.FullName;
                    rblSex.SelectedValue = lector.Gender;
                    tbDepartmentName.Text = lector.DepartmentName;
                    tbBriefInfo.Text = lector.BriefInfo;
                    tbJobPosition.Text = lector.JobPosition;
                }
                this.Title = "编辑讲师信息";
            }

        }
    }

    protected void lbtnSave_Click(object sender, EventArgs e)
    {
        LectorInfo lector = new LectorInfo(LectorID);
        if (!lector.Load())
        {
            lector.ID = Guid.NewGuid();
        }
        lector.BackNvarchar1 = tbBackNvarchar1.Text;
        lector.BackNvarchar2 = tbBackNvarchar2.Text;
        lector.BackNvarchar3 = tbBackNvarchar3.Text;
        if(!string.IsNullOrEmpty(tbBirthday.Text))
        {
            lector.Birthday = Convert.ToDateTime(tbBirthday.Text);
        }
        lector.FullName = tbName.Text;
        lector.Gender = rblSex.SelectedValue;
        lector.BriefInfo = tbBriefInfo.Text;
        lector.DepartmentName = tbDepartmentName.Text;
        lector.JobPosition = tbJobPosition.Text;
        lector.Save();
        

        string script = "<script>alert('保存成功!');refreshParent();window.close();</script>";
        ClientScript.RegisterStartupScript(this.GetType(), "Close", script);
    }
}
